|
|
|
| |
|
|
|
|
You can also add a control to a form by double-clicking the control's Toolbox icon. This places a control of a default size in the center of the form. You can then move and resize the control as desired with the sizing handles, as described in the upcoming section, ''Moving and Resizing a Control." |
|
|
|
|
|
|
|
|
|
|
The procedures used to draw the TextBox control are the same as those for drawing most dcontrols on a form. |
|
|
|
|
|
|
|
|
Setting a Control's Properties |
|
|
|
|
|
|
|
|
After you have added a control to a form, you will usually want to set one or more of the control's properties. Properties are settings that control the appearance and behavior of an object. For the text box you just added, you want to set the Name and Text properties. |
|
|
|
|
|
|
|
|
The Name property is very important. It is used in program code to identify the control. Because a program will likely have many controls of the same type, you can use the control's name property to identify the particular control for which a particular code statement is written. |
|
|
|
|
|
|
|
|
Every control must have a name, which is represented by the value of its Name property. In addition, every control on a particular form must have a unique name, unless it's part of a control array. (Control arrays are covered in detail in Chapter 13, "Working with Control Arrays;" for now, just make sure all your controls on a given form have unique names.) |
|
|
|
|
|
|
|
|
Visual Basic assigns a default name to every control placed on a form. Because this is the first text box you've placed on this form, its default name is Text1. Subsequently placed text boxes would be named Text2, Text3, and so on. It's very good programming practice to change the default control names to be more descriptive. Assume, for example, you have three text boxes on a form that are used to accept a customer's last name, first name, and address. If you change the default names of Text1, Text2, and Text3 to something more descriptive, such as txtLName, txtFName, and txtAddress, it will be much easier to remember what each control's purpose is when you (inevitably) must modify your program's code at some future date. |
|
|
|
|
| |
|
|
|
|
Note that the control names suggested begin with the prefix txt. It's common to begin a control name with a three-character lowercase prefix denoting the type of control; the rest of the name describes the control's purpose. Thus, when debugging program code, it is immediately clear that txtLName refers to a TextBox control that contains last name information. Other commonly used prefixes include lbl for Label controls and cmd for CommandButton controls. |
|
|
|
|
|
|
|
|
|
|
To change the name of the first text box you placed on the form for the Loan Calculator project, you must first make sure the control is selected. The selected control is the one for which properties will be changed in the Properties window. As you'll see a little later, multiple controls can be selected at the same time. You can tell if a control is selected if it has a series of eight sizing handles around its borders. The selected control's name also appears in the Properties window's Object box, which is the drop-down list just below the Properties window's title bar. If the desired control isn't selected, simply click it one time to select it. |
|
|
|
|
|
|
|
|
Now that the control is selected, look at the Properties window. The left column of the Properties window is a list of properties that apply to the selected object at design time. Each |
|
|
|
|
|